<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import { reactive, ref } from "vue";
import { getBigOrder, RawBigOrderData } from "./components/query";
import QuoteChart from "./components/QuoteChart.vue";
import LineChart from "./components/LineChart.vue";
import { formatDate } from "./utils";
const lastUpdated = ref("");
const graphDataList = reactive<RawBigOrderData[]>([]);
// methods
const getBigOrderHandler = () => {
  getBigOrder().then((res) => {
    lastUpdated.value = new Date((res.LastOrderTime - 0) * 1000).toString();
    const item: RawBigOrderData = {
      BigOrderThreshold: (res.BigOrderThreshold - 0) / 10000,
      BuyBigOrderCount: (res.BuyBigOrderCount - 0) / 10000,
      BuyBigOrderCountPeriod: (res.BuyBigOrderCountPeriod - 0) / 10000,
      SellBigOrderCount: (res.SellBigOrderCount - 0) / 10000,
      SellBigOrderCountPeriod: (res.SellBigOrderCountPeriod - 0) / 10000,
      date: formatDate(new Date()),
    };
    graphDataList.push(item);
  });
};
// onCreated
window.setInterval(getBigOrderHandler, 3000);
</script>
<template>
  <h1>近12小时数据</h1>
  <QuoteChart
    :data="graphDataList"
    :params="['BuyBigOrderCount', 'SellBigOrderCount']"
  />
  <LineChart
    :data="graphDataList"
    :params="['BuyBigOrderCount', 'SellBigOrderCount']"
  ></LineChart>
  <h1>近1小时数据</h1>
  <QuoteChart
    :data="graphDataList"
    :params="['BuyBigOrderCountPeriod', 'SellBigOrderCountPeriod']"
  />
  <LineChart
    :data="graphDataList"
    :params="['BuyBigOrderCountPeriod', 'SellBigOrderCountPeriod']"
  ></LineChart>
</template>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
